/**
 * 
 */
package com.sebscape.sebcms.security.domain;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Unique;

import com.sebscape.sebcms.persistence.domain.GenericPersistenceAnnotation;
import com.sebscape.sebcms.persistence.domain.ISelfDescribing;

/**
 * @author Stephen
 *
 */
@GenericPersistenceAnnotation(
	friendlyName = "Roles",
	listFields = { "name", "description", "memberCount" },
	listFieldLabels = { "Name", "Description", "# Members" },
	editFields = { "name", "description", "memberCount" },
	editFieldLabels = { "Name", "Description", "# Members" }
)
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@Unique(name="ROLE_UNIQUE_IDX", members={"name"})
public class Role implements Serializable, ISelfDescribing {
	
	private static final long serialVersionUID = 7049728056182079845L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	
	@Persistent
	private String name;
	
	@Persistent
	private String description;

	@Persistent
	private String specialCode;

	public Role( String name, String description, String specialCode ){
		this.name = name;
		this.description = description;
		this.specialCode = specialCode;
	}
	 public Role( String name, String description ){
		 this.name = name;
		 this.description = description;
	 }
	 public Role(){
		 super();
	 }
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	 
	/**
	 * @return the specialCode
	 */
	public String getSpecialCode() {
		return specialCode;
	}
	
	/**
	 * @param specialCode the code to set
	 */
	public void setSpecialCode(String specialCode) {
		this.specialCode = specialCode;
	}
	
	//////////////////////////////
	// implement ISelfDescribing
	//////////////////////////////
	
	/* (non-Javadoc)
	 * @see com.sebscape.sebcms.persistence.domain.ISelfDescribing#getEditableFieldLabels()
	 */
	@Override
	public Map<String, String> getEditableFieldLabels() {
		Map<String, String> map = new HashMap<String, String>();
		map.put( "name", "text" ); 
		map.put( "description", "textarea" ); 
		return map;
	}

	/* (non-Javadoc)
	 * @see com.sebscape.sebcms.persistence.domain.ISelfDescribing#getEditableFieldNames()
	 */
	@Override
	public List<String> getEditableFieldNames() {
		// TODO Auto-generated method stub
		return Arrays.asList( new String[]{"name","description"});
	}

	/* (non-Javadoc)
	 * @see com.sebscape.sebcms.persistence.domain.ISelfDescribing#getEditablePreferredHtmlInputTypes()
	 */
	@Override
	public Map<String, String> getEditablePreferredHtmlInputTypes() {
		Map<String, String> map = new HashMap<String, String>();
		map.put( "name", "Role Name" ); 
		map.put( "description", "Description" ); 
		return map;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Role))
			return false;
		Role other = (Role) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
 
}
